/*
 * Copyright 2010-2012 Marcin Blazejewski
 *
 * This file is part of Ground0.
 *
 * Ground0 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ground0 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ground0. If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef STUFF_H_
#define STUFF_H_

#include "geometry.hpp"
#include "midlev.hpp"
#include "quat.hpp"
#include "collision.hpp"

#include <list>
#include <vector>
#include <string>
#include <iostream>
#include <GL/gl.h>
#include <GL/glu.h>

using namespace std;


class Dynamics {
private:
    void  add_point_mass(Vector center, float mass);
    Dynamics(const Dynamics &r) {}
    Dynamics& operator =(const Dynamics &r) {}

public:
    float mass;
    float I[3][3];
    float I_inv[3][3];

    Dynamics();
    void  from_cm(class CollisionModel &cm);
    void  collide(Stuff &s1, Stuff &s2, Vector &n, Vector &p1, Vector &p2, float T);
};

class Stuff {
private:
    // selection box size
    float xl, xh, yl, yh, zl, zh;
    GLuint selbox_list;

    void prepare();

public:
    // generic 
    Vector                  pos, prevpos;
    Quaternion              orientation, prev_o;
    Vector                  front;
    Vector                  up;
    float                   scale;

    // visuals / geometry
    Block                  *block;
    
    // collision model
    int                     cidx;    
    float                   cR;
    CollisionModel         *cm;

    // physics
    Dynamics                dyn;
    Vector                  velocity;
    Vector                  rotvel;
    Vector                  _rot_axis;


    // TODO: remove; temporary for asteroid shooter
    int life;
    bool use_grav;
    bool rigid;

    Stuff();
    Stuff(Block *b);
    Stuff(const Stuff &);
    ~Stuff();

    void                     calc_cr();
    bool                     collides_with(Stuff *s, Vector *n = NULL, Vector *p1 = NULL, Vector *p2 = NULL);

    void                     move(float x, float y, float z);
    void                     move(const Vector &dp);
    virtual void             draw();
    virtual void             tick(const float dt);
    void                     draw_sel();
};


#endif

